var main = new Vue({
    el: "#main",
    data: {
        keywords: '',
        songs: [

        ],
        musicUrl: '',
        degs: 0,    //旋转角度
        timer: '',  //计时器
        imgUrl: './images/demo05.jpg',
        comments: [ //评论内容
            {
                uname: '',
                uimg: '',
                ubody: '',
            },
        ]
    },
    methods: {
        musicQuery: function () {
            var that = this;
            axios.get("https://autumnfish.cn/search?keywords=" + this.keywords).then(function (response) {
                that.songs = response.data.result.songs;
            }, function (err) {
                console.log(err);
            })
        },
        playMusic: function (index) {
            clearTimeout(this.timer);
            var that = this;
            // 获取音乐url
            axios.get("https://autumnfish.cn/song/url?id=" + this.songs[index].id).then(function (response) {
                that.musicUrl = response.data.data[0].url;
            }, function (err) {
                console.log(err);
            })
            // 获取音乐封面url
            axios.get("https://autumnfish.cn/song/detail?ids=" + this.songs[index].id).then(function (response) {
                that.imgUrl = response.data.songs[0].al.picUrl;
            }, function (err) {
                console.log(err);
            })
            // 获取评论信息
            axios.get("https://autumnfish.cn/comment/hot?type=0&id=" + this.songs[index].id).then(function (response) {
                for (var i = 0; i < response.data.hotComments.length; i++) {
                    if (i == 0) {
                        that.comments[i].uname = response.data.hotComments[i].user.nickname;
                        that.comments[i].uimg = response.data.hotComments[i].user.avatarUrl;
                        that.comments[i].ubody = response.data.hotComments[i].content;
                    }
                    else {
                        var comment = new Object();
                        comment.uname = response.data.hotComments[i].user.nickname;
                        comment.uimg = response.data.hotComments[i].user.avatarUrl;
                        comment.ubody = response.data.hotComments[i].content;
                        that.comments.push(comment);
                    }
                }

            }, function (err) {
                console.log(err);
            })
        },
        noPlay: function () {
            clearTimeout(this.timer);
        },
        musicPlay: function () {
            var that = this;
            that.timer = setInterval(function () {
                if (that.degs >= 360) {
                    that.degs = 0;
                }
                that.degs++;
            }, 50)
        }
    }
})